import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'

export const EnumSourceType = {
  MANUAL: 0, //(0, "采购"),
  BLACK_HAWK_API: 1, //(1, "黑鹰API");
};
export const EnumSourceTypeText = {
  [EnumSourceType.MANUAL]: "采购", //(0, "采购"),
  [EnumSourceType.BLACK_HAWK_API]: "黑鹰API", //(1, "黑鹰API");
};

// 表单校验
export const rules = reactive({
  customDenomination: [required],
  currencyCode: [required],
  source: [required],
  productNo: [required],
  productName: [required]
})

// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: 'CDK编号',
    field: 'productNo',
    isSearch: true
  },
  {
    label: 'CDK名称',
    field: 'productName',
    isSearch: true
  },
  {
    label: '商品描述',
    field: 'productDescription',
    isSearch: false
  },
  {
    label: '激活方法',
    field: 'redemptionTexts',
    isSearch: false
  },
  {
    label: '兑换方式',
    field: 'redemptionOptions',
    isSearch: false
  },
  {
    label: '库存',
    field: 'stock',
    formatter: (row: any, column: any, cellValue: any)=> {
      return cellValue == null ? "--" : cellValue
    },
    isSearch: false
  },
  {
    label: '是否自定义面值',
    field: 'customDenomination',
    isTable: false,
    form: {
      component: 'Radio'
    }
  },
  {
    label: '更新时间',
    field: 'updateTime',
    formatter: dateFormatter,
    isForm: false
  },
  {
    label: '商品id',
    field: 'id',
    isTable: false,
    isForm: false
  },
  {
    label: '商品URI',
    field: 'entityId',
    isTable: false
  },
  {
    label: '产品线id',
    field: 'productLineId',
    isTable: false
  },
  {
    label: '商品配置id',
    field: 'configurationId',
    isTable: false
  },
  {
    label: '商品UPC',
    field: 'upc',
    isTable: false
  },
  {
    label: '产品生效日期',
    field: 'startDate',
    isTable: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        valueFormat: 'x'
      }
    }
  },
  {
    label: '产品失效日期',
    field: 'endDate',
    isTable: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        valueFormat: 'x'
      }
    }
  },
  {
    label: '国家地区代码',
    field: 'locale',
    isTable: false
  },
  {
    label: '货币',
    field: 'currencyCode'
  },
  {
    label: '固定面值',
    field: 'denominationFixed',
    isForm: false,
    // form: {
    //   component: 'InputNumber',
    //   value: 0
    // }
  },
  {
    label: '最小面值',
    field: 'denominationMin',
    isForm: false,
    // form: {
    //   component: 'InputNumber',
    //   value: 0
    // }
  },
  {
    label: '最大面值',
    field: 'denominationMax',
    // form: {
    //   component: 'InputNumber',
    //   value: 0
    // }
  },
  {
    label: '商品详细数据',
    field: 'productDetailData',
    isTable: false
  },
  {
    label: '来源',
    field: 'source',
    dictType: DICT_TYPE.DIGITAL_CARDKEY_SOURCE,
    dictClass: 'number',
    isSearch: true,
    isForm: false,
    form: {
      component: 'SelectV2'
    }
  },

  {
    label: '商品描述',
    field: 'productDescription',
    isTable: false,
    form: {
      component: 'Editor',
      componentProps: {
        valueHtml: '',
        height: 200
      }
    }
  },
  {
    label: '最小面额',
    field: 'denominationMin',
    isTable: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '最大面额',
    field: 'denominationMax',
    isTable: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '成本',
    field: 'costPrice',
    isTable: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '履行方式',
    field: 'fulfillmentMethod',
    isTable: false
  },
  {
    label: '备注',
    field: 'remark'
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
